#ifndef __ECONOMY_API_H__
#define __ECONOMY_API_H__

#include <map>
#include <mutex>
#include "GameSingleton.h"
#include "Engine/GameGuid.h"
#include "Expand/IPlugin.h"
#include "GameType.h"

namespace PocketSurvival
{
    class AuthPlugin;
    class SubsystemPlayers;
}

using namespace PocketSurvival;
using namespace PocketSurvival::Engine;

namespace Economy
{
    class EconomyAPI : public SimpleSingletonItem
    {
        friend class PocketSurvival::SimpleSingleton;
    private:
        SubsystemPlayers *m_subsystemPlayers;

        AuthPlugin *m_authPlugin;
        
        std::map<GameGuid, uint32_t> m_moneyMap;
        std::mutex m_moneyMapMutex;

        uint32_t m_defaultMoney;

    private:
        EconomyAPI() = default;
        ~EconomyAPI();
        EconomyAPI(const EconomyAPI &) = delete;
        EconomyAPI(EconomyAPI &&) = delete;
        EconomyAPI &operator=(const EconomyAPI &) = delete;
        EconomyAPI &operator=(EconomyAPI &&) = delete;

        void sendHelpMessage(IPlugin::ChatObj &chatObj);
        void sendGuidMessage(const GameGuid& gameGuid, const std::string &message);
        void sendPlayerMessage(PlayerDataPtr &playerDataPtr, const std::string &message);

    public:
        void load();
        void save();

        void setGuidMoney(const GameGuid &guid, uint32_t money);
        uint32_t getGuidMoney(const GameGuid &guid);
        void addGuidMoney(const GameGuid &guid, uint32_t money);
        void decGuidMoney(const GameGuid &guid, uint32_t money);

        void processCmd(IPlugin::ChatObj &chatObj, std::vector<std::string> &cmdDataVec);

    };
    
} // namespace Economy

#endif
